package com.xb.p11_action_provider;

import android.content.Context;
import androidx.core.view.ActionProvider;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

class MyActionProvider extends ActionProvider {
    Context context;

    public MyActionProvider(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    public View onCreateActionView() {
        View view = LayoutInflater.from(context).inflate(R.layout.myactionproovider,null,false);
        Button btn =view.findViewById(R.id.hello);
        btn.setOnClickListener(v -> Toast.makeText(context,"自定动作菜单",Toast.LENGTH_SHORT).show());
        return view;
    }

    //菜单折叠起来的时候，默认调用的方法
    @Override
    public boolean onPerformDefaultAction() {
        Toast.makeText(context,"自定动作菜单2",Toast.LENGTH_SHORT).show();
        return super.onPerformDefaultAction();
    }
    
}
